﻿using System;
using System.Collections;
namespace Moonlite.Data.EditorInterop
{
    [Serializable()]
    public class DeserializedObjectCollection : CollectionBase
    {
        public DeserializedObjectCollection()
        {
        }

        public DeserializedObjectCollection(DeserializedObjectCollection value)
        {
            AddRange(value);
        }

        public DeserializedObjectCollection(IDeserializedObject[] value)
        {
            AddRange(value);
        }

        public IDeserializedObject this[int index]
        {
            get
            {
                return ((IDeserializedObject)(List[index]));
            }
            set
            {
                List[index] = value;
            }
        }

        public int Add(IDeserializedObject value)
        {
            return List.Add(value);
        }

        public void AddRange(IDeserializedObject[] value)
        {
            for (int i = 0; (i < value.Length); i = (i + 1))
            {
                Add(value[i]);
            }
        }

        public void AddRange(DeserializedObjectCollection value)
        {
            for (int i = 0; (i < value.Count); i = (i + 1))
            {
                Add(value[i]);
            }
        }

        public bool Contains(IDeserializedObject value)
        {
            return List.Contains(value);
        }

        public void CopyTo(IDeserializedObject[] array, int index)
        {
            List.CopyTo(array, index);
        }

        public int IndexOf(IDeserializedObject value)
        {
            return List.IndexOf(value);
        }

        public void Insert(int index, IDeserializedObject value)
        {
            List.Insert(index, value);
        }

        public new DeserializedObjectEnumerator GetEnumerator()
        {
            return new DeserializedObjectEnumerator(this);
        }

        public void Remove(IDeserializedObject value)
        {
            List.Remove(value);
        }

        public class DeserializedObjectEnumerator : object, IEnumerator
        {
            private IEnumerator baseEnumerator;
            private IEnumerable temp;

            public DeserializedObjectEnumerator(DeserializedObjectCollection mappings)
            {
                temp = ((IEnumerable)(mappings));
                baseEnumerator = temp.GetEnumerator();
            }

            public IDeserializedObject Current
            {
                get
                {
                    return ((IDeserializedObject)(baseEnumerator.Current));
                }
            }

            object IEnumerator.Current
            {
                get
                {
                    return baseEnumerator.Current;
                }
            }

            public bool MoveNext()
            {
                return baseEnumerator.MoveNext();
            }

            bool IEnumerator.MoveNext()
            {
                return baseEnumerator.MoveNext();
            }

            public void Reset()
            {
                baseEnumerator.Reset();
            }

            void IEnumerator.Reset()
            {
                baseEnumerator.Reset();
            }
        }
    }
}
